package com.feicheng.common.advice;

import com.feicheng.common.exception.SystemException;
import com.feicheng.common.result.ResultInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@ControllerAdvice
public class ControllerAdviceHandler {

    private static final Logger LOG = LoggerFactory.getLogger(ControllerAdviceHandler.class);

    @ResponseBody
    @ExceptionHandler(SystemException.class)
    public ResultInfo handlerSystemException(SystemException e) {
        LOG.warn(e.getMessage());
        return ResultInfo.fail(e.getMessage());
    }

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public ResultInfo handlerException(Exception e) {
        LOG.error("系统发生异常", e);
        return ResultInfo.error("系统出现未知错误！");
    }

}